<?php

/**
 * Users form.
 *
 * @package    sf_sandbox
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class UsersForm extends BaseUsersForm
{
  public function configure()
  {
  	$this->setValidators(array(
	     'login'   => new sfValidatorAnd(
	  		array(
				new sfValidatorString(
					array('required' => true, 'min_length' => 3, 'max_length' => 14),
					array(
						'min_length' => "The login is too short. 3 characters minimum.", 
						'max_length' => "The login is too long. 14 characters maximum", 
					)
				),
				new sfValidatorRegex(
					array('pattern' => '/^[a-zA-Z0-9-]+$/')
				)
			),
			array(),
			array(
				'required' => "The login is required",
				'invalid' => "The nickname could not contain special characters."	
			)
	  ),
	     'mdp'   => new sfValidatorString(
			array('required' => true, 'min_length' => 6, 'max_length' => 20), 
			array(
				'min_length' => "The password is too short. 6 characters minimum.", 
				'max_length' => "The password is too long. 20 characters maximum", 
				'required' => "Password is required", 
				'invalid' => "The password must contains between 6 and 20 characters"
			)
	  ),
	     'repeat-mdp'   => new sfValidatorString(
	  		array('required' => true, 'min_length' => 6, 'max_length' => 20), 
			array(
				'min_length' => "The password is too short. 6 characters minimum.", 
				'max_length' => "The password is too long. 20 characters maximum", 
				'required' => "Password confirmation is required", 
				'invalid' => "The password must contains between 6 and 20 characters"
			)
		),
	     'email'   => new sfValidatorEmail(
	  		array('required' => true), 
			array(
				'required' => "Email is required", 
				'invalid' => "This email isn't correct. Please give a valid one."
			)
	  ),
	  
	 	));
	 	
	 	
	$this->validatorSchema->setPostValidator(
		new sfValidatorSchemaCompare('mdp',  sfValidatorSchemaCompare::EQUAL, 'repeat-mdp', array(), array('invalid' => "The password and password confirmation are different"))
	);
	   
	$this->widgetSchema->setNameFormat('users[%s]');
	$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
	   
  }
  
  public function setup()
  {
  	parent::setup(); 
  	
    $this->setWidgets(array(
      'id'          => new sfWidgetFormInputHidden(),
      'civilite'    => new sfWidgetFormInputHidden(),
      'nom'         => new sfWidgetFormInputHidden(),
      'prenom'      => new sfWidgetFormInputHidden(),
      'email'       => new sfWidgetFormInputText(),
      'login'       => new sfWidgetFormInputText(), 
      'mdp'         => new sfWidgetFormInputPassword(array('label' => 'Mot de passe')),
      'inscription' => new sfWidgetFormInputHidden(),
      'newsletter'  => new sfWidgetFormInputHidden(),
      'type'        => new sfWidgetFormInputHidden(),
   	  'repeat-mdp'  => new sfWidgetFormInputPassword(array('label' => 'Confirmation')),
    ));
  }
}
